package com.xls.pet.query;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import java.sql.Date;
import java.time.LocalDate;

@Getter
@Setter
public class ItemStockQuery {

    private Integer itemId;

    private Integer categoryId;

    /**
     * 1 有库存
     * 2 无库存
     */
    private Integer quantity;

    /**
     * 1 已过期
     * 2 未过期
     * 3 未过期 一天内
     * 4 未过期 一周内
     * 5 未过期 一月内
     * 6 未过期 三月内
     * 7 未过期 半年内
     * 8 未过期 一年内
     */
    private Integer dateRule;

    private Date expirationDateBegin;

    private Date expirationDateEnd;

    @JsonIgnore
    public void setBeginAndEnd(Integer dateRule) {
        if (dateRule == 1) {
            this.expirationDateEnd = Date.valueOf(LocalDate.now().minusDays(1));
        } else if (dateRule == 2) {
            this.expirationDateBegin = Date.valueOf(LocalDate.now());
        } else if (dateRule == 3) {
            this.expirationDateBegin = Date.valueOf(LocalDate.now());
            this.expirationDateEnd = Date.valueOf(LocalDate.now().plusDays(1));
        } else if (dateRule == 4) {
            this.expirationDateBegin = Date.valueOf(LocalDate.now());
            this.expirationDateEnd = Date.valueOf(LocalDate.now().plusWeeks(1));
        } else if (dateRule == 5) {
            this.expirationDateBegin = Date.valueOf(LocalDate.now());
            this.expirationDateEnd = Date.valueOf(LocalDate.now().plusMonths(1));
        } else if (dateRule == 6) {
            this.expirationDateBegin = Date.valueOf(LocalDate.now());
            this.expirationDateEnd = Date.valueOf(LocalDate.now().plusMonths(3));
        } else if (dateRule == 7) {
            this.expirationDateBegin = Date.valueOf(LocalDate.now());
            this.expirationDateEnd = Date.valueOf(LocalDate.now().plusMonths(6));
        } else if (dateRule == 8) {
            this.expirationDateBegin = Date.valueOf(LocalDate.now());
            this.expirationDateEnd = Date.valueOf(LocalDate.now().plusYears(1));
        }
    }

}
